package com.lpe.controller;

import com.lpe.pojo.vo.ResultVo;
import com.lpe.sys.SysCode;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 测试Controller
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("/util")
public class UtilController {

    @RequestMapping("/weather/{city}")
    @ResponseBody
    public ResultVo home(HttpServletRequest request, @PathVariable("city")String city) {

        String appKey = request.getHeader("appKey");

        ResultVo rv = new ResultVo();

        if(StringUtils.isEmpty(appKey)){
            rv.setCode(SysCode.HTTP_CODE_SUCCESS);
            rv.setMsg("AppKey不能为空");
            return rv;
        }

        String weather = "晴";
        rv.setMsg("Success");
        rv.setData(weather);
        rv.setCode(SysCode.HTTP_CODE_SUCCESS);
        return rv;
    }
}
